package com.momoauth.api_client.controller;

import com.momoauth.api_client.config.AlipayConfig;
import com.momoauth.common.tps.aliyun.service.AliPayService;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/pay")
@Api(tags = "支付")
public class PayController {

    /**
     * 支付宝手机网站支付
     * @param response
     */
    @RequestMapping(value = "/alipay", method = RequestMethod.GET)
    public void alipay(HttpServletResponse response) {
        String out_trade_no = "202201010101";
        String total_amount = "0.01";
        AliPayService aliPayService = new AliPayService(
                AlipayConfig.SERVER_URL,
                AlipayConfig.APPID,
                AlipayConfig.PRIVATE_KEY,
                AlipayConfig.FORMAT,
                AlipayConfig.CHARSET,
                AlipayConfig.ALIPAY_PUBLIC_KEY,
                AlipayConfig.SIGNTYPE,
                AlipayConfig.NOTIFY_URL,
                AlipayConfig.RETURN_URL,
                AlipayConfig.PRODUCT_CODE,
                "支付宝手机网站支付",
                "支付宝手机网站支付"
        );
        aliPayService.alipay(response, out_trade_no, total_amount);
    }

    /**
     * 支付宝支付回调地址
     */
    @RequestMapping(value = "/alipay_return")
    public String alipay_return() {
        return "/alipay_return.html";
    }
}
